home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / PICKLIST.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  128 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Definition of classes TPickListPopup & TPickListDialog
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_PICKLIST_H)
  10. #define OWL_PICKLIST_H
  11.  
  12. #if !defined(OWL_DIALOG_H)
  13. #include <owl/dialog.h>
  14. #endif
  15. #if !defined(OWL_LISTBOX_H)
  16. #include <owl/listbox.h>
  17. #endif
  18.  
  19. #if defined(BI_NAMESPACE)
  20. namespace OWL {
  21. #endif
  22.  
  23. // Generic definitions/compiler options (eg. alignment) preceeding the 
  24. // definition of classes
  25. #include <services/preclass.h>
  26.  
  27. //
  28. // class TPickListPopup
  29. // ~~~~~ ~~~~~~~~~~~~~~
  30. // The PickList allows selection of an item from a popup list. The list can
  31. // have an optional title, provided by string or string resource id.
  32. //
  33. // Strings can be added after construction using AddString()
  34. //
  35. // The 0-based selection is returned from Execute(), or can be retrieved later
  36. // using GetResult()
  37. //
  38. class _OWLCLASS TPickListPopup : public TWindow {
  39.   public:
  40.     TPickListPopup(TWindow* parent, const char far* title = 0);
  41.     TPickListPopup(TWindow* parent, uint titleId);
  42.  
  43.     void        ClearStrings();
  44.     int         AddString(const char far* str);
  45.     int         Execute(); // Returns index picked (1 based), 0 if cancelled
  46.     int         GetResult() const;
  47.  
  48.   protected:
  49.     TResult     EvCommand(uint id, THandle hWndCtl, uint notifyCode);
  50.  
  51.   private:
  52.     TPopupMenu  Popup;
  53.     int         Count;
  54.     int         Result;
  55. };
  56.  
  57. //
  58. // class TPickListDialog
  59. // ~~~~~ ~~~~~~~~~~~~~~~
  60. // The PickListDialog allows selection of an item from a list in a dialog with
  61. // OK and Cancel buttons. An initial string list can be provided, and an
  62. // initial selection. Also, the dialog template and title can be overriden.
  63. //
  64. // Strings can be added after construction using AddString()
  65. //
  66. // The 0-based selection is returned from Execute(), or can be retrieved later
  67. // using GetResult()
  68. //
  69. class _OWLCLASS TPickListDialog : public TDialog {
  70.   public:
  71.     TPickListDialog(TWindow*      parent,
  72.                     TStringArray* strings = 0,
  73.                     int           initialSelection = 0,
  74.                     TResId        templateId = 0,
  75.                     const char far* title = 0,
  76.                     TModule*      module = 0);
  77.    ~TPickListDialog();
  78.  
  79.     void          ClearStrings();
  80.     int           AddString(const char far* str);
  81.     int           GetResult() const;
  82.  
  83.   protected:
  84.     void          SetupWindow();
  85.     void          CmOK();
  86.     void          CmCancel();
  87.  
  88.   private:
  89.     TListBox      List;
  90.     int           Result;
  91.     TStringArray* Strings;
  92.     bool          NewedStrings;
  93.  
  94.   DECLARE_RESPONSE_TABLE(TPickListDialog);
  95. };
  96.  
  97. // Generic definitions/compiler options (eg. alignment) following the 
  98. // definition of classes
  99. #include <services/posclass.h>
  100.  
  101. #if defined(BI_NAMESPACE)
  102. } // namespace OWL
  103. #endif
  104.  
  105. //----------------------------------------------------------------------------
  106. // Inline implementation
  107. //
  108.  
  109. //
  110. // Return the result of the selection.
  111. //
  112. inline int
  113. TPickListPopup::GetResult() const
  114. {
  115.   return Result;
  116. }
  117.  
  118. //
  119. // Return the result of the selection.
  120. //
  121. inline int
  122. TPickListDialog::GetResult() const
  123. {
  124.   return Result;
  125. }
  126.  
  127. #endif // OWL_PICKLIST_H
  128.